#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdlib.h>
void childRun()
{
    int cnt  = 5;
    while(cnt--)
    {
      printf("child running...\n");
      sleep(1);
    }
}
int main()
{
  printf("i am process,pid = %d,ppid = %d\n",getpid(),getppid());
  pid_t id = fork();
  if(id == 0)
  {
    childRun();
    printf("child quit...\n");
    exit(123);
  }
  int status  = 0;
  while(1) 
  {
     pid_t rid = waitpid(id,&status,WNOHANG);
     if(rid == 0)
     {
       sleep(1);
       //发送请求成功，但是子进程未退出
       printf("child not quit,please next time!\n");
       //fathDothing()
     }
     else if(rid > 0)
     {
       if(WIFEXITED(status))
       {
         printf("wait success,exit code is : %d\n",WEXITSTATUS(status));
       }
       else 
       {
         printf("wait failed\n");
       }
       break;
     }
     else 
     {
       printf("child quit falied\n");
       break; 
     }
   } 
  return 0;
}

  
  
  





  /*int status = 0;
  pid_t rid = waitpid(id,&status,0);
  if(rid >0)
  {
    if(WIFEXITED(status))
    {
      printf("child quie success,chld exit code = %d\n",WEXITSTATUS(status));
   }
    else 
    {
      printf("child quit unnorimal\n");
    }
  }*/
  
 // printf("rid == %d,status = %d\n",rid,status);
